#include<string>
#include<vector>
using namespace std;
class Solution {
public:
    string reverseMessage(string message) {
        vector<string> tmp;
        string ret;
        int n = message.size();
        size_t start = 0, end = 0;
        while (end < n) {
            while (message[start] == ' ' && start < n) {
                start++;
            }
            if ((end = message.find(' ', start)) != string::npos) {
                tmp.push_back(message.substr(start, end - start));
                start = end;
            }
        }
        if (start < n) {
            tmp.push_back(message.substr(start));
        }
        if (tmp.size() == 0)return ret;
        for (int i = tmp.size() - 1; i > 0; i--) {
            cout << tmp[i] << '*';
            ret += tmp[i];
            ret += ' ';
        }
        return ret += tmp[0];
    }
};